package com.per.yyyFrame.config;

import com.per.yyyFrame.enums.RespCode;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Created with IntelliJ IDEA.
 *
 * @author: yyy
 * Date: 2022/2/7
 * Time: 16:41
 * Description:
 */

public class BizExceptional extends RuntimeException{
  private final List<Map> errorMessage = new ArrayList();

  public BizExceptional() {
  }

  public BizExceptional(String message) {
    super(message);
    Map map=new HashMap();
    map.put("errCode", RespCode.ERROR.getCode());
    map.put("message",message);
    this.errorMessage.add(map);
  }

  public BizExceptional(String message, Throwable cause) {
    super(message, cause);
    Map map=new HashMap();
    map.put("errCode", RespCode.ERROR.getCode());
    map.put("message",message);
    this.errorMessage.add(map);
  }

  @Override
  public Throwable fillInStackTrace() {
    return this;
  }

  @Override
  public String toString() {
    List<String> res = new ArrayList();
    this.errorMessage.forEach((p) -> {
      res.add((String)p.get("message") + "\n");
    });
    return res.toString();
  }

  public List getErrorMsgList(){
    return this.errorMessage;
  }
}
